package com.wn55.hrms.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wn55.hrms.entity.Permission;
import com.wn55.hrms.mapper.PermissionMapper;
import com.wn55.hrms.service.vo.PermissionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionService {
    @Autowired
    PermissionMapper pm;
    public List<PermissionVo> initPermission(){
        return pm.initLoadAllPermission();
    }

    public List<PermissionVo> searchRoleMenu(String name) {
        return pm.searchRoleMenuByEmpName(name);
    }

    public PageInfo<Permission> listPermission(Integer currentPage, Integer pageSize, String name) {
        PageHelper.startPage(currentPage,pageSize);
        List<Permission> list = pm.listByCondition(name);
        return new PageInfo<>(list);
    }

    public List<Permission> loadParentMenu() {
        return pm.listPermissionParent();
    }

    public int updatePermission(Permission permission) {
        return pm.updateByPrimaryKey(permission);
    }

    public int addPermission(Permission permission) {

        return pm.insert(permission);
    }

    public int deletePermission(Long id) {
        return pm.deleteByPrimaryKey(id);
    }
}
